package com.example.yuejian23.yuejian_23.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.yuejian23.yuejian_23.Adapter.JulebuAdapter;
import com.example.yuejian23.yuejian_23.Adapter.PeixunAdapter;
import com.example.yuejian23.yuejian_23.R;
import com.example.yuejian23.yuejian_23.javaBean.JulebuBean;
import com.example.yuejian23.yuejian_23.javaBean.PeixunBean;
import com.example.yuejian23.yuejian_23.service.JulebuService;
import com.example.yuejian23.yuejian_23.service.PeixunService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 王应予 on 2017/10/10.
 */

public class JulebuFragment extends Fragment
{
    RecyclerView recyclerView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.tab04,container,false);

        recyclerView =(RecyclerView) view.findViewById(R.id.julebu);
        recyclerView.setLayoutManager(new LinearLayoutManager(JulebuFragment.this.getContext()));
        showData();

        return view;
    }

    private void showData()
    {

        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://115.159.93.244/new18yuejian/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        JulebuService julebuService=retrofit.create(JulebuService.class);

        Call<List<JulebuBean>> call=julebuService.getList();

        call.enqueue(new Callback<List<JulebuBean>>() {
            @Override
            public void onResponse(Call<List<JulebuBean>> call, Response<List<JulebuBean>> response) {
                List<JulebuBean> julebu=response.body();

                recyclerView.setAdapter(new JulebuAdapter(getActivity(),julebu));

            }

            @Override
            public void onFailure(Call<List<JulebuBean>> call, Throwable t) {

            }
        });

    }
}